#usr/bin/python

from PyQt4 import QtCore
from mpl_toolkits.mplot3d import axes3d
from matplotlib import cm
import matplotlib.pyplot as plt
import numpy as np
from gui import canvas_GL
import BaseController as base
#must import beacause of inheritance
from core.pySpec import PySpecBasis 
from core import pySpec as obj

class canvas_peak_control(base):
	"""
	controller of the peak canvas
	"""
	attributes =('peak','canvas','list_choice')
	def __init__(self, spl, peak, canvas_peak, win):
		"""
		Constructor
		@spl
		@peak
		@win
		@list of choices
		"""
		base.__init__(self, spl, win)
		self.peak = peak
		self.canvas = canvas_peak
		self.list_choice=["associated spectra", "associated chromatogram", "3D view"]
		
		QtCore.QObject.connect( self.canvas.widget().button, QtCore.SIGNAL ( "clicked()" ), self.choosen)
		
		
	def choosen(self):
		if self.canvas.widget().combobox.currentText() == self.list_choice[0]:
			for spectr in self.spl.getSpectra():
				if spectr.get_t_max() < self.peak.get_rt_max() and spectr.get_t_min > self.peak.get_rt_min():
					can = spectr.plot()
					#can.show()
					self.win.addMdiSubWindow(can)
		elif self.canvas.widget().combobox.currentText() ==self.list_choice[1]:
			
			self.win.addMdiSubWindow(self.peak.get_chromato().plot(self.peak.get_X_data(), self.peak.get_Y_data()))
			
		elif self.canvas.widget().combobox.currentText() ==self.list_choice[2]:
				
			fig = plt.figure()
			ax = axes3d.Axes3D(fig)
			X, Y, Z = axes3d.get_test_data(0.05)
			ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
			plt.show()
			wid =canvas_GL.canvas_GL(self.spl, self.peak)#
			self.win.addMdiSubWindow(wid, " ".join(["3D plotting of", str(self.peak.get_trans())]))

			

